package com.burns.java.io.RandomAccessFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class WriteText2File {

	public static void main(String[] args) {
		try {
			File f = new File("d:" + File.separator + "test.txt");
			RandomAccessFile raf = new RandomAccessFile(f, "rw");// 读写模式，如果该路径不存在会自动创建
			String name1 = "jim";
			int age1 = 20;
			String name2 = "Tom";
			int age2 = 30;
			raf.writeBytes(name1);
			raf.writeInt(age1);
			raf.writeBytes(name2);
			raf.writeInt(age2);
			raf.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
